﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AlarmManagePlatform.UC
{
    internal partial class GasCircuit : UserControl
    {
        internal event EventHandler Event_EnabledChanged;
        internal GasCircuit()
        {
            InitializeComponent();
            gasCircuitPara1.Enabled = false;
            cbGasType.CheckedChanged += CbGasType_CheckedChanged;
        }

        internal Model.DB.tb_ParaInfo ParaInfo
        {
            set {
                gasCircuitPara1.ParaInfo = value;
            }
        }

        private void CbGasType_CheckedChanged(object sender, EventArgs e)
        {
            gasCircuitPara1.Enabled = cbGasType.Checked;
            Event_EnabledChanged?.Invoke(sender, e);
        }

        internal new bool Enabled
        {
            get { return cbGasType.Checked; }
            set { cbGasType.Checked = value;
                gasCircuitInfo.enabled = value;
            }
        }
        
        RelationsLMP.Model.SimplifiedProcess.GasCircuitInfo gasCircuitInfo;
        internal RelationsLMP.Model.SimplifiedProcess.GasCircuitInfo GasCircuitInfo
        {
            get {
                gasCircuitInfo.enabled = cbGasType.Checked;
                gasCircuitInfo.stdGasDesc = gasCircuitPara1.IndicatingValue.ToString() + gasCircuitPara1.ParaInfo.Unit;
                gasCircuitInfo.stdConcentration = gasCircuitPara1.StdGasConcentration;
                gasCircuitInfo.WaitingTime = gasCircuitPara1.WaitingTime;
                gasCircuitInfo.IndicatingValue = gasCircuitPara1.IndicatingValue;
                return gasCircuitInfo; }
            set
            {
                if (value == null) return;
                gasCircuitInfo = value;
                cbGasType.Text = Relations.Common.Methods.GetEnumDescription(gasCircuitInfo.type);
                cbGasType.Checked = gasCircuitInfo.enabled;
                gasCircuitPara1.StdGasConcentration = gasCircuitInfo.stdConcentration;
                gasCircuitPara1.WaitingTime = gasCircuitInfo.WaitingTime;
            }
        }
    }
}
